import collections


class Solution(object):
    def differByOne(self, dict):
        now = collections.defaultdict(list)
        m = len(dict[0])

        def find(s1, s2):
            c = 0
            for i in range(m):
                if s1[i] == s2[i]:
                    c += 1
            return c == m - 1

        base = 10 ** 9 + 7
        for index, word in enumerate(dict):
            t = 0
            for i in range(len(word)):
                t = (t + (ord(word[i]) - ord('a') + 1) * pow(27, i, base)) % base
            for i in range(len(word)):
                val = (t - (ord(word[i]) - ord('a') + 1) * pow(27, i, base)) % base
                if now[val]:
                    if index not in now[val]:
                        for node in now[val]:
                            if find(dict[index], dict[node]):
                                return True
                        now[val].append(index)

                else:
                    now[val].append(index)
        return False
